Skip to content

#402 - date_parser: reject the out-of-range dates, cast the scalar inputs, explicit error on the other inputs - #403

Merged
njoubert-cleverage merged 2 commits into
mainfrom
402
Nov 3, 2026
Merged

njoubert-cleverage merged 2 commits into
mainfrom
402

Conversation

@njoubert-cleverage

Copy link
Copy Markdown
Member

Description

Fixes #402.

  • Out-of-range dates: after \DateTime::createFromFormat(), DateParserTransformer checks \DateTime::getLastErrors(). Its warnings (e.g. "The parsed date was invalid", "The parsed time was invalid") throw an UnexpectedValueException naming the value. Until now, 2024-02-31 gave 2024-03-02, 2024-13-01 gave 2025-01-01 and 25:61 was accepted. A leap day is still accepted.
  • Inputs: a scalar (e.g. an int timestamp with the U format) or a \Stringable is cast to string. An array or another object throws an UnexpectedValueException with the type, instead of a raw TypeError. The falsy values, \DateTime and \DateTimeImmutable are handled as before.

Requirements

  • Documentation updates
    • Reference
    • Cookbooks
    • Changelog
  • Unit tests

Breaking changes

None in the API. An out-of-range date, silently shifted until now, makes the transformer fail, as the documentation said for a value that cannot be parsed.

🤖 Generated with Claude Code

…puts, explicit error on the other inputs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@njoubert-cleverage
njoubert-cleverage requested a review from a team as a code owner November 3, 2026 09:44
@njoubert-cleverage
njoubert-cleverage merged commit af8e908 into main Nov 3, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

date_parser: out-of-range dates (2024-02-31, 25:61) accepted, TypeError on non-string inputs

1 participant